package com.tongji.showroom.view.twoD
{
	import com.tongji.showroom.events.ChangePropertyEvent;
	import com.tongji.showroom.utils.ConstVariableInventory;
	import com.tongji.showroom.utils.PopUpAdmin;
	import com.tongji.showroom.view.titleWindows.SingleFurnitureTitleWindow;
	import com.tongji.showroom.view.titleWindows.SingleFurnitureTitleWindowMediator;
	import com.tongji.showroom.vo.Picture;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.ui.Keyboard;
	
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import mx.events.FlexMouseEvent;
	import mx.managers.PopUpManager;
	
	import spark.components.Image;

	/**
	 * 
	 * @author yanghanbing
	 * 2011/08/
	 */ 
	public class Furniture extends UIComponent
	{
		private var _content:BitmapData;

		public function get content():BitmapData
		{
			return _content;
		}

		public function set content(value:BitmapData):void
		{
			_content = value;
		}

		private var _hostProduct:Object;

		public function get hostProduct():Object
		{
			return _hostProduct;
		}

		public function set hostProduct(value:Object):void
		{
			_hostProduct = value;
		}
		
		private var _filter:DropShadowFilter;

		public function get filter():DropShadowFilter
		{
			return _filter;
		}

		public function set filter(value:DropShadowFilter):void
		{
			_filter = value;
		}

		private var _distortSprite:DistortSprite;

		public function get distortSprite():DistortSprite
		{
			return _distortSprite;
		}

		public function set distortSprite(value:DistortSprite):void
		{
			_distortSprite = value;
		}

		private var singleFurnitureTitleWindow:SingleFurnitureTitleWindow = new SingleFurnitureTitleWindow();

		public function Furniture(hostProduct:Object, content:BitmapData)
		{
			this._content = content;
			this._hostProduct = hostProduct;
			
			distortSprite = new DistortSprite(new Bitmap(content));			
			this.addChild(distortSprite);			
			
			this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			
		}

		protected function mouseOverHandler(event:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
			this.addEventListener(MouseEvent.CLICK, clickHandler);
			this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}
		
		protected function mouseMoveHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub			
		}
		
		protected function clickHandler(event:MouseEvent):void
		{
			//派发事件到SecondStepEditSceneMediator中，建立titlewindow
			dispatchEvent(new ChangePropertyEvent(ChangePropertyEvent.CHANGE_FURNITURE, event.currentTarget as Furniture));	
		}
		
		protected function mouseOutHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			
		}
		
		public function setFilter(filter:DropShadowFilter):void
		{
			this._filter = filter;
			var filterArray:Array = new Array();
			filterArray.push(filter);
			distortSprite.setFilter(filter);
		}
		
		public function setColor(bitmapdata:BitmapData):void
		{
			this.removeChild(distortSprite);
			distortSprite = new DistortSprite(new Bitmap(bitmapdata));
			this.addChild(distortSprite);
			this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
		}
		
		public function clone():Furniture
		{
			var newFurniture:Furniture = new Furniture(this._hostProduct, this.content.clone());
			return newFurniture;
		}
	}
}